// ----------------------------------
// RSDK Project: Sonic 2
// Script Description: BG Animation Object
// Script Author: Christian Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

// ========================
// Aliases
// ========================

private alias object.propertyValue : object.hide // set from editor
private alias object.value0 	   : object.timer

// Priority
public alias 0 : PRIORITY_BOUNDS
public alias 1 : PRIORITY_ACTIVE
public alias 2 : PRIORITY_ALWAYS
public alias 3 : PRIORITY_XBOUNDS
public alias 4 : PRIORITY_XBOUNDS_DESTROY
public alias 5 : PRIORITY_INACTIVE
public alias 6 : PRIORITY_BOUNDS_SMALL
public alias 7 : PRIORITY_ACTIVE_SMALL

// Ink Effects
public alias 0 : INK_NONE
public alias 1 : INK_BLEND
public alias 2 : INK_ALPHA
public alias 3 : INK_ADD
public alias 4 : INK_SUB

// Flip Directions
public alias 0 : FLIP_NONE
public alias 1 : FLIP_X
public alias 2 : FLIP_Y
public alias 3 : FLIP_XY


// ========================
// Static Values
// ========================

public value BGAnimation_currentPreview = 0


// ========================
// Events
// ========================

event ObjectUpdate
	object.timer++
	object.timer &= 0x1FF

	Sin(temp0, object.timer)
	if temp0 > 0
		if temp0 < 32
			screen.yoffset = 256
		else
			screen.yoffset = 0
		end if
	else
		if temp0 > -32
			screen.yoffset = 512
		else
			screen.yoffset = 768
		end if
	end if
end event


event ObjectDraw
	if object.hide == false
		// This script doesn't only do BG animation, it also deals with drawing the zone preview at the bottom right of the screen
		// BGAnimation_currentPreview is set by the Menu Control object
		temp0 = screen.xcenter
		temp0 -= 180
		if temp0 > 0
			temp0 = 0
		end if
		temp0 += screen.xcenter
		DrawSpriteScreenXY(14, temp0, 198)
		DrawSpriteScreenXY(BGAnimation_currentPreview, temp0, 198)
	end if
end event


event ObjectStartup
	LoadSpriteSheet("LevelSelect/Icons.gif")

	// Set all BG Animation objects to active
	// (There should only ever be one in a scene, though)
	foreach (TypeName[BG Animation], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].priority = PRIORITY_ACTIVE
	next

	SpriteFrame(56, -12, 32, 24, 0, 50) 	// Sonic vibin'	 - #0
	
	// Zone previews
	SpriteFrame(56, -12, 32, 24, 1, 85)		// EHZ			 - #1
	SpriteFrame(56, -12, 32, 24, 34, 85)	// CPZ			 - #2
	SpriteFrame(56, -12, 32, 24, 67, 85)	// ARZ			 - #3
	SpriteFrame(56, -12, 32, 24, 100, 85)	// CNZ			 - #4
	SpriteFrame(56, -12, 32, 24, 133, 85)	// HTZ			 - #5
	SpriteFrame(56, -12, 32, 24, 166, 85)	// MCZ			 - #6
	SpriteFrame(56, -12, 32, 24, 199, 85)	// HPZ			 - #7
	SpriteFrame(56, -12, 32, 24, 180, 1)	// OOZ			 - #8
	SpriteFrame(56, -12, 32, 24, 213, 1)	// MTZ			 - #9
	SpriteFrame(56, -12, 32, 24, 180, 26)	// SCZ			 - #10
	SpriteFrame(56, -12, 32, 24, 213, 26)	// WFZ			 - #11
	SpriteFrame(56, -12, 32, 24, 180, 51)	// DEZ			 - #12
	SpriteFrame(56, -12, 32, 24, 213, 51)	// Special Stage - #13

	SpriteFrame(32, -24, 80, 50, 0, 0) // Selection frame - #14

	// Default to the EHZ icon
	BGAnimation_currentPreview = 1
end event


// ========================
// Editor Events
// ========================

event RSDKEdit
	if editor.returnVariable == true
		switch editor.variableID
		case EDIT_VAR_PROPVAL // property value
			checkResult = object.propertyValue
			break
			
		case 0 // hidden
			checkResult = object.propertyValue
			break
			
		end switch
	else
		switch editor.variableID
		case EDIT_VAR_PROPVAL // property value
			object.propertyValue = editor.variableValue
			break
			
		case 0 // hidden
			object.propertyValue = editor.variableValue
			break
			
		end switch
	end if
end event


event RSDKDraw
	DrawSprite(1)
	DrawSprite(0)
end event


event RSDKLoad
	LoadSpriteSheet("LevelSelect/Icons.gif")
	SpriteFrame(56, -12, 32, 24, 0, 50)
	SpriteFrame(32, -24, 80, 50, 0, 0)

	AddEditorVariable("hidden")
	SetActiveVariable("hidden")
	AddEnumVariable("false", false)
	AddEnumVariable("true", true)
end event
